<?php
/**

 */
 
header("Content-type: text/html; charset=utf-8");

// Adjust to your timezone
date_default_timezone_set('Asia/Shanghai');

// Report all PHP errors
error_reporting(-1);

// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/Autoload.php';

// Instanciate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
//	ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,
	ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 
	'aps_development.pem'
);

$tklist = array (
	'c430e2704fca3895adec4ffadd59fa0c72c1e4c17f35391a92c25644838ad2b5',     // 4s test
	'e7645581b114074cfd393f3a6f88c9dd692239c6745b55b33344c075210ab804',		// ipad4 lance
);

// Set the Provider Certificate passphrase
//$push->setProviderCertificatePassphrase('123456');

// Set the Root Certificate Autority to verify the Apple remote peer
//$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

// Connect to the Apple Push Notification Service
$push->connect();

foreach ($tklist as $tk)
{


	// Instantiate a new Message with a single recipient
	$message = new ApnsPHP_Message_Custom($tk);

	// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
	// over a ApnsPHP_Message object retrieved with the getErrors() message.
	$message->setCustomIdentifier("Message-Badge-3");

	// Set badge icon to "3"
	$message->setBadge(5);

	$content = $_GET['msg'];
	// Set a simple welcome text
	//Hello APNs-enabled device!
	//
	$message->setText($content);

	// Play the default sound
	$message->setSound('push_sound.aiff');

	// Set a custom property
	$message->setCustomProperty('acme2', array('bang', 'whiz'));

	// Set another custom property
	$message->setCustomProperty('acme3', array('bing', 'bong'));

	// Set the expiry value to 30 seconds
	$message->setExpiry(30);

	//$message->setLaunchImage('a1.jpg');

	// Set the "View" button title.
	$message->setActionLocKey('xxxx!');

	// Add the message to the message queue
	$push->add($message);


}

// Send all messages in the message queue
$push->send();


// Disconnect from the Apple Push Notification Service
$push->disconnect();


// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
	var_dump($aErrorQueue);
}
?>